package com.nullpointer.xchat.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nullpointer.xchat.R;
import com.nullpointer.xchat.object.LanguageRoom;

public class RoomAdapter extends ArrayAdapter<LanguageRoom> {

	/**
	 * ViewHolder class for layout.<br />
	 * <br />
	 * Auto-created on 2014-12-12 10:49:17 by Android Layout Finder
	 * (http://www.buzzingandroid.com/tools/android-layout-finder)
	 */
	private static class ViewHolder {
		public final LinearLayout rootView;
		public final TextView tvLanguage;
		public final TextView tvNum;

		private ViewHolder(LinearLayout rootView, TextView tvLanguage,
				TextView tvNum) {
			this.rootView = rootView;
			this.tvLanguage = tvLanguage;
			this.tvNum = tvNum;
		}

		public static ViewHolder create(LinearLayout rootView) {
			TextView tvLanguage = (TextView) rootView
					.findViewById(R.id.tv_language);
			TextView tvNum = (TextView) rootView.findViewById(R.id.tv_num);
			return new ViewHolder(rootView, tvLanguage, tvNum);
		}
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final ViewHolder vh;
		if (convertView == null) {
			View view = mInflater.inflate(R.layout.item_lv_room, parent, false);
			vh = ViewHolder.create((LinearLayout) view);
			view.setTag(vh);
		} else {
			vh = (ViewHolder) convertView.getTag();
		}

		LanguageRoom item = getItem(position);
		vh.tvLanguage.setText(item.getLanguageName());
		if (item.isSelected()) {
			vh.rootView.setBackgroundResource(R.color.fbb25e);
		} else {
			vh.rootView
					.setBackgroundResource(R.drawable.bg_ff8800_pressed_fbb25e);
		}
		// vh.tvNum.setText(item.getNumUser());
		return vh.rootView;
	}

	private LayoutInflater mInflater;

	// Constructors
	public RoomAdapter(Context context, List<LanguageRoom> objects) {
		super(context, 0, objects);
		this.mInflater = LayoutInflater.from(context);
	}

	public RoomAdapter(Context context, LanguageRoom[] objects) {
		super(context, 0, objects);
		this.mInflater = LayoutInflater.from(context);
	}
}
